package edu.umb.cs.antmanager.common;

import java.io.File;

public final class Constants {
	// Agent's status
	public static final String STATUS_IDLE = "idle";
	public static final String STATUS_BUSY = "busy";
	// Test's status
	public static final String TEST_STATUS_UNTESTED = "untested";
	public static final String TEST_STATUS_RUNNING = "running";
	public static final String TEST_STATUS_FINISHED = "finished";
	
	//Task types
	public static final int TASK_TYPE_STATUS = 1;
	public static final int TASK_TYPE_EXECUTE = 2;
	public static final int TASK_TYPE_SHUTDOWN = 3;
	public static final int TASK_TYPE_RESTART = 4;
	
	public static final String ANT_MANAGER_HOME = getAntManagerHome();

	// RMI Registry port
	public static final int SERVER_PORT = 1099;
	// Agent's RMI service name
	public static final String AGENT_SERVER_NAME = "AntAgent";
	// Manager's RMI service name
	public static final String MANAGER_SERVER_NAME = "AntManager";
	// Code base for RMI to locate class
	public static final String CODE_BASE = getCodeBase();
	// The file contains the security policy
	public static final String SECURITY_FILE = ANT_MANAGER_HOME+"\\security.policy";

	private static String getAntManagerHome(){
		String home = System.getenv("ANT_MANAGER_HOME");
		if(home==null) home = new File("").getAbsolutePath();
		return home;
	}
	
	private static String getCodeBase(){
		File build = new File("build/classes");
		File jar = new File(ANT_MANAGER_HOME+"/lib/ant-manager.jar");
		if(build.exists()) return build.toURI().toString();
		return jar.toURI().toString();
	}
}
